%% Compute empirical coverage and associated p-values for a list of nu

function [empirical_cov_list, cov_p_value_list] = ecf_over_nu(hat_theta, rep_base_se2, hat_vartheta, rep_val_se2, meta_nu_list, cov_stat_sim)
%INPUT: baseline and validation study data, list of meta analyst's nu, simulated sample of coverage statistics cov_stat_sim
%OUTPUT: empirical coverage frequencies evaluated at each nu in meta_nu_list, corresponding coverage p-values cov_p_value_list
    
    % Initialization
    K = size(meta_nu_list, 2);
    empirical_cov_list = zeros(1, K);
    cov_p_value_list = zeros(1, K);

    for k = 1:length(meta_nu_list)
        % Set the value of meta analyst's nu
        meta_nu = meta_nu_list(k);
    
        % Compute posterior means and variances for tau
        [bar_tau, bar_V_tau] = compute_posterior_moments(hat_theta, rep_base_se2, meta_nu);
        
        % Check whether the validation study estimates are located in the predicted interval
        [predict_se, empirical_cov, cov_p_value] = check_CI(hat_vartheta, rep_val_se2, bar_tau, bar_V_tau, meta_nu, cov_stat_sim);
    
        % Save the results
        empirical_cov_list(1, k) = empirical_cov;
        cov_p_value_list(1, k) = cov_p_value;
    end
end